nlt_type3[i] not initialized when get_nonlinear_transform() == false
#220
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Dear library maintainers. I found this bug while working on my work-project, but I do not have any knowledge of how jpeg2000 compression works internally, so this is a "contextual fix". Here my observations and analysis:
Symptoms
I am working with images stored on AWS HealthImaging. AWS is transcoding medical data to jpeg2000 compressed images. AWS also computes CRC32 checksums on the decompressed image data. While working on a data-loader, I noticed that CRC32 sums randomly did not match.
I turned to
valgrindand analyzed my loader and traced the issue to the lineOpenJPH/src/core/codestream/ojph_tile.cpp
Line 421 in a0ae0ee
for which
valgrindreported that this "conditional jump depends on unitialized data".Analysis
By adding some more if-statements, I found out that the uninitialized data meant was
nlt_type3[comp_num]. This seems to get initialized in this code section:OpenJPH/src/core/codestream/ojph_tile.cpp
Lines 270 to 280 in a0ae0ee
From what I could derive, jpeg2000 images can use the "non linear transform" optionally, but if it is not used,
nlp->get_nonlinear_transform(i, bd, is, nlt_type3[i])returnsfalse, andnlt_type3[i]is never set. I quickly checked theparam_nlt::nonlinearitytype and saw that it seems to define the valueOJPH_NLT_NO_NLTwhich seems to match this case.Proposed solution
Set
nlt_type3[i] = param_nlt::nonlinearity::OJPH_NLT_NO_NLT;when nonlinear-transform is disabled.I have no idea if this is "correct" but it seems to fix the issue. With the fix, I now can reliably decode images from AWS HealthImaging with no hickups and
valgrindis also happy.